package com.example.shopping.repository;

import com.example.shopping.entity.User;
import org.hibernate.annotations.SQLInsert;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface UserRepository extends JpaRepository<User,Integer> {
    public User findByUid(Integer uid);


    // 模糊查询 username、mailingaddress、ssex
    @Query("SELECT u FROM User u WHERE " +
            "(:username IS NULL OR u.username LIKE %:username%) AND " +
            "(:mailingaddress IS NULL OR u.mailingaddress LIKE %:mailingaddress%) AND " +
            "(:ssex IS NULL OR u.ssex = :ssex)")
    Page<User> findUsersWithDynamicCriteria(
            @Param("username") String username,
            @Param("mailingaddress") String mailingaddress,
            @Param("ssex") String ssex,
            Pageable pageable);

}
